import Vue from 'vue'
import VueRouter from 'vue-router'
import Register from '../views/Register'     //
import Index from '../views/Index.vue'     //
import Book_message from '../views/Book_message.vue'
import User_message from '../views/User_message'
import Add_user from '../views/Add_user.vue'
import Add_book from '../views/Add_book.vue'
import home from '../views/home.vue'
import log_in from '../views/log_in'
import SubRecord from '../views/SubRecord'
import BookStore from '../views/BookStore'
import Mybook from '../views/Mybook'
Vue.use(VueRouter)

const routes = [
  {  path: '/',
    redirect: '/Login'
  },
// 登录
  {
    path: '/Login',
    name: 'Login',
    component: log_in
    // component: Index,
    
  },
  // 注册
  {
    path: '/Register',
    name: 'Register',
    component:Register
  },
  // 首页
  {
    path: '/Index',
    name: 'Index',
    component:Index,
    redirect: "Index/home",
    children:[
      // 个人信息
      {
        path:'home',
        name:home,
        component:home,
        // redirect: "/home",
        // component:Base_seach
      },
      // 图书信息
      {
        path:'book_message',
        component:Book_message
      },
      //用户信息 
      {
        path:'user_message',
        component:User_message
      }, 
      // 增加用户
      {
        path:'add_user',
        component:Add_user
      },
      // 增加图书
      {
        path:'add_book',
        component:Add_book
      },
      // 订阅记录
      {
        path:'SubRecord',
        component:SubRecord
      },
      // 书库
      {
        path:'book_store',
        component:BookStore
      },
      // 我的书架
      {
        path:'my_book',
        component:Mybook
      },
    ]
  }
]
//全局前置路由守卫————初始化的时候被调用、每次路由切换之前被调用
// router.beforeEach((to, from, next) => {
//   //如果路由需要跳转
//   // if (to.path==='/') {
//   //   return next()
//   //   const tokenstr=window.sessionStorage.getItem('ismaind')
//   //   if (!tokenstr) {
//   //     return next('/login')
//   //   }
//   //     // 否则，放行
//   // }
//   // next()
// })

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
